package com.iory.tianwangterminator;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.TextView;
//import android.widget.VideoView;
import android.widget.VideoView;

public class RtPlayActivity extends Activity {
	
	
	VideoView videoView ;
	LinearLayout mainLayout;
	private Dialog dialog;
	OnPreparedListener onPreparedListerner;
	private int i = 0;
	private MediaController mediaController;
	private TextView title;
	private String name ="";
	private String rtsp = "";
	
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rtplay);
        name  = getIntent().getStringExtra("CameraName");
        rtsp  =  getIntent().getStringExtra("CameraRtsp");
        mainLayout = (LinearLayout) findViewById(R.id.main);
        title = (TextView) findViewById(R.id.title);
        title.setText(name);
        
        onPreparedListerner = new OnPreparedListener() {
			
			@Override
			public void onPrepared(MediaPlayer mp) {
				// TODO Auto-generated method stub
				videoView.setBackgroundColor(Color.argb(0, 0, 255, 0));
				
				dialog.dismiss();
			}
		};
        dialog=ProgressDialog.show(this, "视频加载中...", "请您稍候");
        videoView = (VideoView) findViewById(R.id.video_view);
        videoView.setOnPreparedListener(onPreparedListerner);
        PlayRtspStream(rtsp);
//        mediaController = new MediaController(this);
//        mediaController.setMediaPlayer(videoView);
      
//        videoView.setVideoURI(uri);   
//        videoView.setMediaController(mediaController);
//        videoView.requestFocus();
//        videoView.start();
//        mediaController.show();
        
    }
    
    //play rtsp stream
    private void PlayRtspStream(String rtspUrl){
    	videoView.setVideoURI(Uri.parse(rtspUrl));
    	videoView.requestFocus();
    	videoView.start();
    	//mediaController.show();
    }
    
    @Override

    protected void onResume() {

    super.onResume();

    videoView.seekTo(i);

    videoView.start();

    }

    @Override

    protected void onStop() {

    super.onStop();

    videoView.pause();

    i = videoView.getCurrentPosition();

    }
}